﻿using System;
using System.Windows.Media.Imaging;
using SSG.View;

namespace SSG
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        #region Console and status "logging"
        /// <summary>
        /// Implementing console / status bar logging
        /// </summary>
        private class MainWindowConsoleAndStatus : ConsoleAndStatus
        {
            private readonly MainWindow _window = null;

            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="w"></param>
            public MainWindowConsoleAndStatus(MainWindow w)
            {
                if (w == null) throw new ArgumentNullException("w");
                this._window = w;
            }

            /// <summary>
            /// Status bar available?
            /// </summary>
            /// <returns></returns>
            public override bool HasStatusBar()
            {
                return this._window._stOverallStatus != null;
            }

            /// <summary>
            /// Console available?
            /// </summary>
            /// <returns></returns>
            public override bool HasConsole()
            {
                return this._window._tbConsole != null;
            }

            /// <summary>
            /// Write a status message.
            /// </summary>
            /// <param name="msg"></param>
            /// <param name="severity"></param>
            public override void WriteStatusMsg(string msg, Severity severity)
            {
                if (string.IsNullOrEmpty(msg)) return;
                if (this._window == null || this._window._sbitText == null) return;
                BitmapImage image = this.SeverityToBitmapImage(severity);
                this._window._sbitText.Text = msg;
                this._window._sbitImage.Source = image;
                this.LastStatusBarMessage = DateTime.Now;
                this.WriteConsoleMsg(msg, severity);
            }

            /// <summary>
            /// Write a console message
            /// </summary>
            /// <param name="msg"></param>
            /// <param name="severity"></param>
            public override void WriteConsoleMsg(string msg, ConsoleAndStatus.Severity severity)
            {
                if (this._window._tbConsole == null) return;
                this._window._tbConsole.Text = severity.ToString() + ": " + msg + "\n" + this._window._tbConsole.Text;
            }

            /// <summary>
            /// Clear the status bar message.
            /// </summary>
            public override void ClearStatusBar()
            {
                if (this._window == null || this._window._sbitText == null) return;
                this._window._sbitText.Text = null;
                this._window._sbitImage.Source = null;
            }
        }
        #endregion Console and status "logging"
    }
}